Activity Tracker Data - How hight difference affects running speed

This report shows how hight difference affects the running speed of a person using acitivty data of a sports tracker.

Read and explore data

# Which layer needed
st_layers("activity_6531531145.gpx") # track_points needed
## Driver: GPX 
## Available layers:
##     layer_name     geometry_type features fields
## 1    waypoints             Point        0     23
## 2       routes       Line String        0     12
## 3       tracks Multi Line String        1     12
## 4 route_points             Point        0     25
## 5 track_points             Point     2805     27
# Read data:
p = read_sf("activity_6531531145.gpx", layer = "track_points")

# Convert to CH1903+ LV95
p <- st_transform(p, crs = 2056)

# When was the measurement?
summary(p$time)
##                  Min.               1st Qu.                Median 
## "2021-04-01 15:54:12" "2021-04-01 16:24:34" "2021-04-01 16:56:15" 
##                  Mean               3rd Qu.                  Max. 
## "2021-04-01 16:59:40" "2021-04-01 17:36:13" "2021-04-01 18:10:28"
plot(p$time)

The duration of the activity was 2.2711111 hours.

Calculate timelag, steplength, speed and hight difference

Time lag is measured in seconds, euclidian steplength in meters, speed in km/h and hight difference in meters.

Timelag

# Timelag
p$timelag <- as.integer(difftime(lead(p$time), p$time, units = "secs"))
summary(p$timelag)
##    Min. 1st Qu.  Median    Mean 3rd Qu.    Max.    NA's 
##   1.000   1.000   2.000   2.916   4.000  85.000       1
ggplot(p, aes(x = timelag)) +
  geom_histogram(binwidth = 1) +
  theme_bw()
## Warning: Removed 1 rows containing non-finite values (stat_bin).

Time difference is between 1 and 85 seconds.

Euclidian distance

# Euclidian distance
options(digits=2)
cords <- st_coordinates(p$geometry)

p$E <- cords[,1]
p$N <- cords[,2]

p$steplength <- sqrt(
  (p$E - lead(p$E))^2 + (p$N - lead(p$N))^2
)

The total distance tracked was 15829 meters.

Speed

# Speed
p$speed_ms <- (p$steplength / p$timelag)
p$speed_kmh <- (p$speed_ms * 3.6)


p$speed_kmh_smooth_03 <- rollmean(p$speed_kmh, k = 3, fill = NA, allign = "left")
p$speed_kmh_smooth_05 <- rollmean(p$speed_kmh, k = 5, fill = NA, allign = "left")
p$speed_kmh_smooth_10 <- rollmean(p$speed_kmh, k = 10, fill = NA, allign = "left")

p %>%
  gather(k, Geschwindigkeit, speed_kmh : speed_kmh_smooth_10) %>%
  ggplot(aes(time, Geschwindigkeit, col = k)) +
  geom_line() +
  theme_bw() +
  theme(legend.position = "bottom") +
  labs(title = "Speed diagram\n", x = "\ntime [hh:mm]", y = "speed [kmh]\n" )
## Warning: attributes are not identical across measure variables;
## they will be dropped
## Warning: Removed 19 row(s) containing missing values (geom_path).

ggplotly()

Speed strongly depends on the used k-value in rollmeans.

Including Plots

You can also embed plots, for example:

Note that the echo = FALSE parameter was added to the code chunk to prevent printing of the R code that generated the plot.